package com.xzy.controller.f;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import sun.security.validator.ValidatorException;

import java.io.IOException;

/**
 * 异常处理
 *
 * @author xzy
 * @date 2021/11/1613:19
 */
@Slf4j
@ControllerAdvice
public class MyExceptionHandler {

    /*
     * @ControllerAdvice 将当前类标识为异常处理组件
     */

    /**
     * 处理 IOException
     *
     * @param exception -
     * @param model     -
     * @return -
     */
    @ExceptionHandler(IOException.class)
    public String handel1(Exception exception, Model model) {
        log.info("处理IOException...");
        model.addAttribute("exception", exception);
        return "error";
    }

    @ExceptionHandler({IllegalArgumentException.class, ValidatorException.class})
    public void handel2(Exception exception, Model model) {
        log.info("处理IllegalArgumentException或ValidatorException");
    }

}
